#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion



using System;
using System.Drawing;
using System.Drawing.Drawing2D;

using IPSim.Util;

namespace IPSim.GUI.Devices
{
    /// <author>Edward Smit</author>
    public class LineController: IController
    {
        #region Members

        protected LineDevice device;

        #endregion

        #region Methods

        public LineController(LineDevice line)
        {
            device = line;
        }

        bool IController.IsInside(System.Drawing.Point p)
        {
            GraphicsPath gp = new GraphicsPath();
            Pen pen = new Pen(device.BorderColor, device.BorderWidth + 4);
            pen.StartCap = device.StartCap;
            pen.EndCap = device.EndCap;
            gp.AddLine(device.EndPoint, device.StartPoint);
            return gp.IsOutlineVisible(p, pen);
        }

        void IController.DrawSelection(System.Drawing.Graphics g)
        {
         /*   int borderWidth = 3;

            Rectangle r = new Rectangle(
                controlledDevice.Location.X - borderWidth, controlledDevice.Location.Y - borderWidth,
                controlledDevice.Size.Width + (borderWidth * 2), controlledDevice.Size.Height + (borderWidth * 2));

            HatchBrush brush = new HatchBrush(HatchStyle.SmallCheckerBoard, Color.LightGray, Color.Transparent);
            Pen p = new Pen(brush, borderWidth);
            g.DrawRectangle(p, r);*/

            int borderWidth = 1;
            int selectionSize = 4;
            HatchBrush brush = new HatchBrush(HatchStyle.Percent80, Color.Gray, Color.Transparent);
            Pen p = new Pen(brush, borderWidth);
            Size size = new Size(10,10);
            Rectangle rect;
            rect = new Rectangle(device.StartPoint.X - selectionSize, device.StartPoint.Y - selectionSize, 2 * selectionSize, 2 * selectionSize);
            g.DrawRectangle(p, rect);
            rect = new Rectangle((device.StartPoint.X + device.EndPoint.X) / 2 - selectionSize, (device.StartPoint.Y + device.EndPoint.Y) / 2 - selectionSize, 2 * selectionSize, 2 * selectionSize);
            g.DrawRectangle(p, rect);
            rect = new Rectangle(device.EndPoint.X - selectionSize, device.EndPoint.Y - selectionSize, 2 * selectionSize, 2 * selectionSize);
            g.DrawRectangle(p, rect);
        }


        #endregion

        #region Properties


        BaseDevice IController.ControlledDevice
        {
            get { return device; }
        }

        #endregion

        #region Events


        #endregion     


    }
}
